package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.object.pojo.MachineBatteryBound;
import com.tbit.uqbike.service.business.MachineBatteryBoundService;
import com.tbit.uqbike.webmanager.dao.data.MachineBatteryBoundDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆电池绑定表(MachineBatteryBound)表服务实现类
 *
 * @author jing
 * @since 2020-12-04 10:32:13
 */
@Service("machineBatteryBoundService")
public class MachineBatteryBoundServiceImpl implements MachineBatteryBoundService {
    @Resource
    private MachineBatteryBoundDao machineBatteryBoundDao;

    /**
     * 通过ID查询单条数据
     *
     * @param machineBatteryBoundId 主键
     * @return 实例对象
     */
    @Override
    public MachineBatteryBound queryById(Integer machineBatteryBoundId) {
        return this.machineBatteryBoundDao.queryById(machineBatteryBoundId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<MachineBatteryBound> queryAllByLimit(int offset, int limit) {
        return this.machineBatteryBoundDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param machineBatteryBound 实例对象
     * @return 实例对象
     */
    @Override
    public MachineBatteryBound insert(MachineBatteryBound machineBatteryBound) {
        this.machineBatteryBoundDao.insert(machineBatteryBound);
        return machineBatteryBound;
    }

    /**
     * 修改数据
     *
     * @param machineBatteryBound 实例对象
     * @return 实例对象
     */
    @Override
    public MachineBatteryBound update(MachineBatteryBound machineBatteryBound) {
        this.machineBatteryBoundDao.update(machineBatteryBound);
        return this.queryById(machineBatteryBound.getMachineBatteryBoundId());
    }

    /**
     * 通过主键删除数据
     *
     * @param machineBatteryBoundId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer machineBatteryBoundId) {
        return this.machineBatteryBoundDao.deleteById(machineBatteryBoundId) > 0;
    }

    @Override
    public void insertBatch(List<MachineBatteryBound> machineBatteryBounds) {
        machineBatteryBoundDao.insertBatch(machineBatteryBounds);
    }

    @Override
    public Boolean queryByUserCode(String userCode) {
        return 1 == machineBatteryBoundDao.getByUserCode(userCode);
    }

    @Override
    public List<MachineBatteryBound> queryPage(MachineBatteryBound machineBatteryBound) {
        return machineBatteryBoundDao.queryAll(machineBatteryBound);
    }

    @Override
    public MachineBatteryBound queryByCode(String userCode) {
        List<MachineBatteryBound> machineBatteryBounds = machineBatteryBoundDao.queryAll(new MachineBatteryBound(null, userCode));
        if (machineBatteryBounds.size() == 0) {
            return null;
        }
        return machineBatteryBounds.get(0);
    }

    @Override
    public MachineBatteryBound queryByNO(String batteryNO) {
        return machineBatteryBoundDao.queryAll(new MachineBatteryBound(batteryNO, null)).get(0);
    }

    @Override
    public void deleteByUserCode(MachineBatteryBound machineBatteryBound) {
        machineBatteryBoundDao.deleteByUserCode(machineBatteryBound);
    }
}